<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use app\service\billService;
use app\service\commonService;
use app\service\roominfoService;
use app\service\apiService;
use app\service\communityService;
ini_set('max_execution_time','0');
class Test extends Controller{

    public function test(){
        $data=array(
            'first'=>array('value'=>urlencode("您好,您已购买成功"),'color'=>"#743A3A"),
            'name'=>array('value'=>urlencode("商品信息:微时代电影票"),'color'=>'#EEEEEE'),
            'remark'=>array('value'=>urlencode('永久有效!密码为:1231313'),'color'=>'#FFFFFF'),
        );
    }

    public function roombilldel(){
        $api = new apiService(config('app')['roombilldel'], 'https://openapi.alipay.com/gateway.do');
        $token="202007BBb5f8b77753a44991b5e7179ea5df1E83";
        $community_id="ARYYP7RQA3301";
        $batch_id=date('YmdHis', time()).\util\Tool::getRandomStr(6);
        
        $arr=array(27,28);
        $billlist=Db::table("bill")->where("id","in",$arr)->select();
        $res = $api->roomBilldel2(json_encode([ 'community_id' =>  $community_id,  'token' => $token]),json_encode($billlist));
        var_dump($res);
    }
    public function roombilladd(){
        $api = new apiService(config('app')['roombilladd'], 'https://openapi.alipay.com/gateway.do');
        $token="202007BBb5f8b77753a44991b5e7179ea5df1E83";
        $community_id="ARYYP7RQA3301";
        $batch_id=date('YmdHis', time()).\util\Tool::getRandomStr(6);
        
        $arr=array(2,3);
        $billlist=Db::table("bill")->where("id","in",$arr)->select();
        $res = $api->roomBillAdd2(json_encode(['batch_id' => $batch_id, 'community_id' =>  $community_id,  'token' => $token]),json_encode($billlist));
        var_dump($res);
    }
    
    public function roomdel(){
        $api = new apiService(config('app')['delroom'], 'https://openapi.alipay.com/gateway.do');
        $token="202007BBb5f8b77753a44991b5e7179ea5df1E83";
        $community_id="ARYYP7RQA3301";
        $batch_id=date('YmdHis', time()).\util\Tool::getRandomStr(6);
        $arr=array(4,5);
        $roomlist=Db::table("roominfo")->where("id","in",$arr)->select();
        $res = $api->delRoom2(json_encode(['batch_id' => $batch_id, 'community_id' =>  $community_id, 'token' => $token]),json_encode($roomlist));
        var_dump($res);
    }
    
	public function roomadd(){
       $api = new apiService(config('app')['addroom'], 'https://openapi.alipay.com/gateway.do');
       $token="202007BBb5f8b77753a44991b5e7179ea5df1E83";
       //$arr=array(8,9);
       $roomlist=Db::table("roominfo")->where("id","in",$arr)->select();
       $batch_id="20200728190243MA4HMN";
       $community_id="ARYYP7RQA3301";
       $res = $api->addRoom2(json_encode(['batch_id' => $batch_id, 'community_id' =>  $community_id, 'token' => $token]),json_encode($roomlist));
       var_dump($res);
        
    }
    
	public function billquery(){
		$out_room_id="20201115210344JX4A2Q6A";//20190704104041UE3FSYMH
		$info = Db::table("roominfo")->where('out_room_id',$out_room_id)->find();
		
		echo "<pre>";
		//var_dump($info);
		$token = (new billService())->billinfoToken($info["community_id"]);
		$api = new apiService(config('app')['roombilllist'], 'https://openapi.alipay.com/gateway.do');
		$res = $api->roomBillList(json_encode(['community_id' =>  $info['community_id'], 'out_room_id' => $info['out_room_id'],'batch_id' => "", 'bill_status' => 'WAIT_PAYMENT',  'cost_type' => '' , 'acct_period' => '' , 'release_day' => '' ,'token' => $token]));
		var_dump($res);
	}
	public function delbill(){
        
        $bill_entry_id="20210208103034YC5A4B";
        $billinfo=Db::table("bill")->where("bill_entry_id",$bill_entry_id)->find();
        //var_dump($billinfo);die;
        $community_id=$billinfo["community_id"];
        //$community_id="AO0HJV5Y53301";
        $token = (new billService())->billinfoToken($community_id);
        $api = new apiService(config('app')['roombilldel'], 'https://openapi.alipay.com/gateway.do');
        $res = $api->roomBillDel(json_encode(['community_id' =>  $community_id, 'bill_entry_id' => $bill_entry_id, 'token' => $token]));
        var_dump($res);
    }
}